﻿
using RTW.DAL;
using RTW.OA.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RTW.OA.Areas.Common.Servers
{
    public class CarServers
    {
        private readonly IRepository<vehicle_car> vehicle_carRepository;

        public CarServers()
        {
            vehicle_carRepository = new DapperRepository<vehicle_car>();

        }

        public List<vehicle_car> GetData()
        {
            var datas = vehicle_carRepository.GetAllEnumerable();

            return datas.ToList();
        }

        public vehicle_car GetModelById(string id)
        {
            return vehicle_carRepository.GetById(id);
        }


        internal void Add(vehicle_car model)
        {
            vehicle_carRepository.Insert(model);
        }

        internal void Update(vehicle_car model)
        {
            vehicle_carRepository.Update(model);
        }

        internal void Del(string id)
        {
            vehicle_carRepository.DeleteByIds(id);
        }


        internal List<SelectListItem> GetV_TYPE()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_carRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=9");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }



        internal List<SelectListItem> GetCAR_USER()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_carRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=76");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }



        internal List<SelectListItem> GetV_MOT_SMS_TYPE()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_carRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=79");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }



        internal List<SelectListItem> GetV_INSURE_SMS_TYPE()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_carRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=75");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }



        internal List<SelectListItem> GetV_DEPART()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_carRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=68");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }



        internal List<SelectListItem> GetV_ONWER()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_carRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=90");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }



        internal List<SelectListItem> GetV_CARUSER()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_carRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=90");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }



        internal List<SelectListItem> GetV_NATURE()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_carRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=23");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }



        internal List<SelectListItem> GetV_BINSURE_SMS_TYPE()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_carRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=93");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }
    }
}